import csv
import random

def assign_labels(input_file, output_file):

    with open(input_file, 'r') as f:
        reader = csv.reader(f)
        next(reader)
        ids = [row[0].strip() for row in reader if row]

    random.shuffle(ids)

    total_nodes = len(ids)
    base_count = total_nodes // 10
    remainder = total_nodes % 10

    labels = []
    for label in range(1, 11):
        count = base_count + 1 if label <= remainder else base_count
        labels.extend([label] * count)

    labeled_data = list(zip(ids, labels))

    with open(output_file, 'w', newline='') as f:
        writer = csv.writer(f)
        writer.writerow(['ID', 'LABEL'])
        writer.writerows(labeled_data)

if __name__ == "__main__":
    assign_labels('./Graph500/Graph500_nodes.csv', './Graph500_nodes.csv')